import React from 'react';
import { Redirect, useLocation } from 'umi';
import Login from '@/pages/Login';
export default function Auth(props: any) {
  const { pathname } = useLocation();
  // 登录使用token来进行判断  localStorage 里面是否有token 有的话就是已登录的状态，没有就是未登录
  const token = localStorage.token;

  if (!token && pathname !== '/login') {
    return <Redirect to="/login" />;
  }
  if (token && pathname === '/login') {
    return <Redirect to="/list1" />;
  }
  if (pathname === '/login') {
    return <Login />;
  }
  return <>{props.children}</>;
}
